home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / gle / util / surf / gsurface.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-29  |  16.9 KB  |  698 lines

  1. /* Command decoding, user interface, calls hide */
  2. #include "general.h"
  3. #include "gsurface.h"
  4. #ifdef unix
  5. #define VAXC 1
  6. #endif
  7. #ifdef VAXC
  8. #define huge
  9. #define farmalloc malloc
  10. #define farfree free 
  11. #endif
  12. #ifdef unix
  13. char *strlwr(char *);
  14. #endif
  15. char *(*gtxt)[];   /* gtxt is a pointer to an array of poiter to char */
  16. int ngtxt=0;
  17. int gle_debug;
  18. int noscreenio;
  19.  
  20. FILE *df;
  21.  
  22. int hide(float huge *z,int nx, int ny, float minz, float maxz, struct surface_struct *sff);
  23. int scr_end(void);
  24. typedef char *TOKENS[];
  25. int token(char *lin,TOKENS tok,int *ntok,char *outbuff);
  26. int hide_enddefaults(void);
  27.  
  28. int gle_abort(char *s);
  29. int init_memory(void);
  30. int scr_init(void);
  31. int text_expand(int x);
  32. int token_space(void);
  33. int hide_defaults(void);
  34. int pass_line(void);
  35. char *gletop();
  36. char *getstrv(void);
  37. char *sdup(char *s);
  38. int text_load(char *fname);
  39. int text_free(void);
  40. int do_help(char *s);
  41. int int_edt(char *fname);
  42. int pass_title(void);
  43. int pass_cube(void);
  44. int pass_top(void);
  45. int pass_bot(void);
  46. int pass_marker(void);
  47. int pass_droplines(void);
  48. int pass_riselines(void);
  49. int pass_back(void);
  50. int pass_right(void);
  51. int pass_base(void);
  52. int pass_axis(void);
  53. int pass_anytitle(void);
  54.  
  55. int getstr(char *s);
  56. float getf(void);
  57. int geton(void);
  58. FILE *myfopen(char *fname, char *mode);
  59. int pass_data(int *nx, int *ny, float *zmin, float *zmax);
  60. extern int trace_on,this_line;
  61. int ngerror;
  62. char input_file[80];
  63.  
  64. int batch_only=false;
  65. char glearg0[66];
  66. char gleroot[60];
  67. static int xsample,ysample;
  68. #ifdef unix
  69. #include "../../glepath.h"
  70. #endif
  71. main(int argc, char **argv)
  72. {
  73.     char dtype[60];
  74.     char fname[60],*ss;
  75.     int i;
  76.  
  77.     i=1;
  78.     trace_on = false;
  79.  
  80. /*---------------------------------------------------------------------------*/
  81.     strcpy(gleroot,argv[0]);
  82. #ifdef unix
  83.     dtype[0] = 0;
  84.     ss = getenv("GLE_TOP");
  85.     if (ss==NULL) ss = GLEPATH;
  86.     strcpy(gleroot,ss);
  87. #endif
  88. #ifdef __TURBOC__
  89.     ss = strchr(gleroot,'\\');
  90.     if (ss==NULL) gle_abort("Unable to locate files AGRV[0] wrong");
  91.     for (;strchr(ss+1,'\\')!=NULL;) ss = strchr(ss+1,'\\');
  92.     *(ss+1) = 0;
  93. #endif
  94.     strcpy(fname,"test.sur");
  95.     init_memory(); /* saves some memory for emergencies */
  96.     if (argc>1) strupr( argv[1] );
  97.     if (argc>1) strcpy(fname, argv[1]);
  98.     for (i=1;i<argc; i++) {
  99.         strupr(argv[i]);
  100.         if (strncmp(argv[i],"-B",2)==0)  batch_only = true;
  101.     }
  102.     strlwr(fname);
  103.     if (!batch_only) scr_init();
  104.     if (strchr(fname,'.')==NULL) strcat(fname,".sur");
  105.     strcpy(input_file,fname);
  106.     text_expand(50); /* Initially allocate 500 lines of text */
  107.     text_load(fname);
  108.     /* IF VAX THEN JUST CALL DRAW_HIDDEN */
  109.     if (batch_only) draw_hidden();
  110.     else int_edt(fname);
  111.     if (!batch_only) scr_end();
  112. }
  113. static char inbuff[200];
  114. static char tkbuff[500];
  115. static char *tk[500];
  116. static int ntok,ct;
  117. static struct surface_struct sf;
  118. static float zmin = 10e10,zmax = -10e10;
  119. static float huge *z;
  120. static int nx,ny;
  121. static int insurf,gotsurf;
  122. static double dxmin,dymin,dxmax,dymax;
  123. double zclipmin,zclipmax;
  124. int zclipminset,zclipmaxset;
  125. draw_hidden()
  126. {
  127.     int i,dri,al;
  128.     static char *space_str = " ";
  129.     
  130.     xsample = 1; ysample = 1;
  131.     zclipmin = 0;  zclipminset = false;
  132.     zclipmax = 0;  zclipmaxset = false;
  133.  
  134.     dxmin = dymin = dxmax = dymax = 0;
  135.     zmin = 10e10; zmax = -10e10;
  136.     ngerror = 0;
  137.     token_space();
  138.     for (i=0;i<500;i++) tk[i] = space_str;
  139.     insurf = false; gotsurf = false;
  140.     hide_defaults();
  141.     for (dri=1;dri<=ngtxt;dri++) {
  142.         strcpy(inbuff, (*gtxt)[dri]);
  143.         al = strlen(inbuff);
  144.         if (trace_on) gprint("Source | %s \n",inbuff);
  145.         token(inbuff,tk,&ntok,tkbuff);
  146.         this_line = dri;
  147.         pass_line();
  148.     }
  149.     if (!gotsurf) {
  150.         gprint("Expecting BEGIN SURFACE ... END SURFACE \n");
  151.         return;
  152.     }
  153.     if (nx==0 || ny==0) {
  154.         gprint("No zdata to plot \n");
  155.         return;
  156.     }
  157.     if (zclipminset || zclipmaxset) {
  158.         for (i=0;i<nx*ny;i++) {
  159.             if (zclipminset) if (z[i]<zclipmin) z[i] = zclipmin;
  160.             if (zclipmaxset) if (z[i]>zclipmax) z[i] = zclipmax;
  161.         }
  162.         if (zclipminset) zmin = zclipmin;
  163.         if (zclipmaxset) zmax = zclipmax;
  164.     }
  165.     hide_enddefaults();
  166.  
  167.     hide(z,nx,ny,zmin,zmax,&sf);    
  168. }
  169. #define kw(k) if (strcmp(tk[ct],k)==0) 
  170. char *getstrv()
  171. {
  172.     char *s;
  173.     if (ct>=ngtxt) { gprint("Expecting string \n"); return NULL;}
  174.     s = sdup(tk[++ct]);
  175.     if (*s == '"') {    /* remove quotes if exist */
  176.         strcpy(s,tk[ct]+1);
  177.         s[strlen(s)-1] = 0;
  178.     }
  179.     return s;
  180. }        
  181. getstr(char *s)
  182. {
  183.     if (ct>=ngtxt) { gprint("Expecting Color or Lstyle\n"); return;}
  184.     strncpy(s,tk[++ct],11);
  185. }        
  186. float getf()
  187. {
  188.     if (ct>=ngtxt) gprint("Expecting Number\n");
  189.     return atof(tk[++ct]);
  190. }
  191. int geton()
  192. {
  193.     if (ct>=ngtxt) gprint("Expecting ON | OFF\n");
  194.     ct++;
  195.     if (strcmp(tk[ct],"ON")==0) return true;
  196.     if (strcmp(tk[ct],"OFF")==0) return false;
  197.     gprint("Expecting ON | OFF, asuming ON\n");
  198.     return true;
  199. }
  200. pass_line()
  201. {
  202.     int i;
  203. /*    for (i=1; i<ntok; i++) printf("Token {%s} \n",tk[i]); */
  204.     ct = 1;    /* current token */
  205.  
  206.     if (ntok<1) return;
  207.     kw("BEGIN") {if (strcmp(tk[++ct],"SURFACE")==0) insurf = true; return; }
  208.     if (!insurf) return;
  209.     gotsurf = true;
  210.          kw("END") {if (strcmp(tk[++ct],"SURFACE")==0) insurf = false;}
  211.     else kw("SIZE") {sf.screenx = getf(); sf.screeny = getf();}
  212.     else kw("TITLE") pass_title();
  213.     else kw("CUBE") pass_cube();
  214.     else kw("DATA") {pass_data(&nx,&ny,&zmin,&zmax);    }
  215.     else kw("ROTATE") {sf.xrotate = getf(); sf.yrotate = getf(); sf.zrotate = getf();} 
  216.     else kw("EYE") {sf.eye_x = getf(); sf.eye_y = getf(); sf.vdist = getf();} 
  217.     else kw("VIEW") {sf.eye_x = getf(); sf.eye_y = getf(); sf.vdist = getf();} 
  218.     else kw("HARRAY") sf.maxh = getf();
  219.     else kw("ZCLIP") pass_zclip();
  220.     else kw("SKIRT") sf.skirt_on = geton();
  221.     else kw("XLINES") sf.xlines_on = geton();
  222.     else kw("YLINES") sf.ylines_on = geton();
  223.     else kw("TOP") pass_top();
  224.     else kw("UNDERNEATH") pass_bot();
  225.     else kw("HIDDEN") sf.hidden_on = geton();
  226.     else kw("MARKER") pass_marker();
  227.     else kw("POINTS") pass_points();
  228.     else kw("DROPLINES") pass_droplines();
  229.     else kw("RISELINES") pass_riselines();
  230.     else kw("HIDDEN") sf.hidden_on = geton();
  231.     else kw("BASE") pass_base();
  232.     else kw("BACK") pass_back();
  233.     else kw("RIGHT") pass_right();
  234.     else if (strstr(tk[1],"AXIS")!=NULL)  pass_axis();
  235.     else if (strstr(tk[1],"TITLE")!=NULL)  pass_anytitle(); 
  236.  
  237.     if (ct<ntok) {
  238.         gprint("Extra parameters on end of line {%s} \n",tk[ct]);
  239.      }
  240. }
  241. pass_title()
  242. {
  243.     sf.title = getstrv();
  244.     for (ct++;ct<=ntok;ct++) {
  245.         kw("HEI") sf.title_hei = getf();
  246.         else kw("DIST") sf.title_dist = getf();
  247.         else kw("COLOR") getstr(sf.title_color);
  248.         else gprint("Expecting one of HEI, DIST, COLOR , found {%s} \n",tk[ct]);
  249.     }
  250. }
  251. pass_anytitle()
  252. {
  253.     struct axis_struct *ax;
  254.     if (*tk[ct]=='X') ax = &sf.xaxis;
  255.     if (*tk[ct]=='Y') ax = &sf.yaxis;
  256.     if (*tk[ct]=='Z') ax = &sf.zaxis;
  257.     
  258.     ax->title = getstrv();
  259.     for (ct++;ct<=ntok;ct++) {
  260.         kw("HEI") ax->title_hei = getf();
  261.         else kw("DIST") ax->title_dist = getf();
  262.         else kw("COLOR") getstr(ax->title_color);
  263.         else gprint("Expecting one of HEI, DIST, COLOR , found {%s} \n",tk[ct]);
  264.     }
  265. }
  266. pass_cube()
  267. {
  268.     for (ct++;ct<=ntok;ct++) {
  269.         kw("ON") sf.cube_on = true;
  270.         else kw("OFF") sf.cube_on = false;
  271.         else kw("NOFRONT") sf.cube_front_on = false;
  272.         else kw("FRONT") sf.cube_front_on = geton();
  273.         else kw("LSTYLE") getstr(sf.cube_lstyle);
  274.         else kw("COLOR") getstr(sf.cube_color);
  275.         else kw("XLEN") sf.sizex = getf();
  276.         else kw("YLEN") sf.sizey = getf();
  277.         else kw("ZLEN") sf.sizez = getf();
  278.         else gprint("Expecting one of OFF, XLEN, YLEN, ZLEN, FRONT, LSTYLE, COLOR, found {%s} \n",tk[ct]);
  279.     }
  280.  
  281. }
  282. pass_zclip()
  283. {
  284.     for (ct++;ct<=ntok;ct++) {
  285.         kw("MIN") { zclipmin = getf(); zclipminset = true; }
  286.         else kw("MAX") { zclipmax = getf(); zclipmaxset = true; }
  287.         else gprint("Expecting one of MIN, MAX found {%s} \n",tk[ct]);
  288.     }
  289. }
  290. pass_back()
  291. {
  292.     for (ct++;ct<=ntok;ct++) {
  293.         kw("YSTEP") sf.back_ystep = getf();
  294.         else kw("ZSTEP") sf.back_zstep = getf();
  295.         else kw("LSTYLE") getstr(sf.back_lstyle);
  296.         else kw("COLOR") getstr(sf.back_color);
  297.         else kw("NOHIDDEN") sf.back_hidden = false;
  298.         else gprint("Expecting one of YSTEP, ZSTEP, LSTYLE, COLOR found {%s} \n",tk[ct]);
  299.     }
  300. }
  301. pass_right()
  302. {
  303.     for (ct++;ct<=ntok;ct++) {
  304.         kw("ZSTEP") sf.right_zstep = getf();
  305.         else kw("XSTEP") sf.right_xstep = getf();
  306.         else kw("LSTYLE") getstr(sf.right_lstyle);
  307.         else kw("COLOR") getstr(sf.right_color);
  308.         else kw("NOHIDDEN") sf.right_hidden = false;
  309.         else gprint("Expecting one of ZSTEP, XSTEP, LSTYLE, COLOR found {%s} \n",tk[ct]);
  310.     }
  311. }
  312. pass_base()
  313. {
  314.     for (ct++;ct<=ntok;ct++) {
  315.         kw("XSTEP") sf.base_xstep = getf();
  316.         else kw("YSTEP") sf.base_ystep = getf();
  317.         else kw("LSTYLE") getstr(sf.base_lstyle);
  318.         else kw("COLOR") getstr(sf.base_color);
  319.         else kw("NOHIDDEN") sf.base_hidden = false;
  320.         else gprint("Expecting one of XSTEP, YSTEP, LSTYLE, COLOR found {%s} \n",tk[ct]);
  321.     }
  322. }
  323. pass_droplines() /* toplines lstyle color hidden */
  324. {
  325.     sf.droplines = true;
  326.     for (ct++;ct<=ntok;ct++) {
  327.         kw("LSTYLE") getstr(sf.droplines_lstyle);
  328.         else kw("COLOR") getstr(sf.droplines_color);
  329.         else kw("HIDDEN") sf.droplines_hidden = true;
  330.         else gprint("Expecting one of LSTYLE, COLOR , found {%s} \n",tk[ct]);
  331.     }
  332.  
  333. }
  334. pass_riselines() /* toplines lstyle color hidden */
  335. {
  336.     sf.riselines = true;
  337.     for (ct++;ct<=ntok;ct++) {
  338.         kw("LSTYLE") getstr(sf.riselines_lstyle);
  339.         else kw("COLOR") getstr(sf.riselines_color);
  340.         else kw("HIDDEN") sf.riselines_hidden = true;
  341.         else gprint("Expecting one of LSTYLE, COLOR , found {%s} \n",tk[ct]);
  342.     }
  343.  
  344. }
  345. pass_top() /* top lstyle color off */
  346. {
  347.     for (ct++;ct<=ntok;ct++) {
  348.         kw("LSTYLE") getstr(sf.top_lstyle);
  349.         else kw("COLOR") getstr(sf.top_color);
  350.         else kw("ON") sf.top_on = true;
  351.         else kw("OFF") sf.top_on = false;
  352.         else gprint("Expecting one of OFF, LSTYLE, COLOR , found {%s} \n",tk[ct]);
  353.     }
  354. }
  355. pass_bot() 
  356. {
  357.     sf.bot_on = true;
  358.     for (ct++;ct<=ntok;ct++) {
  359.         kw("LSTYLE") getstr(sf.bot_lstyle);
  360.         else kw("COLOR") getstr(sf.bot_color);
  361.         else kw("ON") sf.bot_on = true;
  362.         else kw("OFF") sf.bot_on = false;
  363.         else gprint("Expecting one of ON, OFF, LSTYLE, COLOR , found {%s} \n",tk[ct]);
  364.     }
  365. }
  366. pass_marker() 
  367. {
  368.     getstr(sf.marker);
  369.     for (ct++;ct<=ntok;ct++) {
  370.         kw("COLOR") getstr(sf.marker_color);
  371.         else kw("HEI") sf.marker_hei = getf();
  372.         else gprint("Expecting MARKER markername COLOR c HEI h, found {%s} \n",tk[ct]);
  373.     }
  374. }
  375. pass_axis()
  376. {
  377.     struct axis_struct *ax=NULL;
  378.     if (*tk[ct]=='X') ax = &sf.xaxis;
  379.     if (*tk[ct]=='Y') ax = &sf.yaxis;
  380.     if (*tk[ct]=='Z') ax = &sf.zaxis;
  381.     if (ax==NULL) { gprint("Expecting xaxis,yaxis,zaxis,  \n"); return;}
  382.  
  383.     for (ct++;ct<=ntok;ct++) {
  384.              kw("MIN") {ax->min = getf(); ax->minset = true;}
  385.         else kw("MAX") {ax->max = getf(); ax->maxset = true;}
  386.         else kw("DTICKS") ax->step = getf();
  387.         else kw("TICKLEN") ax->ticklen = getf();
  388.         else kw("LEN") ax->ticklen = getf();
  389.         else kw("COLOR") getstr(ax->color);
  390.         else kw("STEP") ax->step = getf();
  391.         else kw("HEI") ax->hei = getf();
  392.         else kw("OFF") ax->on = false;
  393.         else kw("ON") ax->on = true;
  394.         else kw("NOFIRST") ax->nofirst = true;
  395.         else kw("NOLAST") ax->nolast = true;
  396.          else gprint("Expecting HEI, DIST, COLOR , TICKLEN, MIN, MAX, STEP, found {%s} \n",tk[ct]);
  397.     }
  398. }
  399. static char buff[2032];
  400. FILE *myfopen(char *fname, char *mode);
  401. int alloc_zdata(int nx, int ny);
  402. alloc_zdata(int nx, int ny)
  403. {
  404.     if (z!=NULL) farfree(z);
  405.     z = farmalloc((long) nx * ((long) ny+1) * sizeof(float));
  406.     if (z==NULL) {
  407.         gprint("Unable to allocate enough memory for datafile\n");
  408.         return true;
  409.     }
  410.     return false;
  411. }
  412. double getkeyval(char *buff,char *k);
  413. double getkeyval(char *buff,char *k)
  414. {
  415.     char *s;
  416.     s = strstr(buff,k);
  417.     if (s!=NULL) return atof(s+strlen(k));
  418.     return 0.0;
  419. }
  420. pass_data(int *nx, int *ny, float *zmin, float *zmax)    /* data test.z [nx ny] */
  421. {    
  422.     double v;
  423.     long x,y,xx,yy;
  424.     int c,b,mx,my,xcnt,ycnt;
  425.     char *s;
  426.     char *fname;
  427.     int i;
  428.  
  429.     xx = yy = x = y = 0;
  430.     fname = getstrv();
  431.      *nx = 0; *ny = 0;
  432.     for (ct++;ct<=ntok;ct++) {
  433.         kw("NX") *nx = getf();
  434.         else kw("NY") *ny = getf();
  435.         else kw("XSAMPLE") xsample = getf();
  436.         else kw("YSAMPLE") ysample = getf();
  437.         else kw("SAMPLE") {xsample = getf(); ysample = xsample; }
  438.         else gprint("Wanted DATA file.Z  XSAMPLE YSAMPLE SAMPLE NX NY. Found {%s} \n",tk[ct]);
  439.     }
  440.     if (*nx != 0) {
  441.         mx = (*nx - 1)/xsample + 1;
  442.         my = (*ny - 1)/ysample + 1;
  443.     }
  444.     xcnt = xsample; ycnt = ysample;
  445.  
  446.     if (nx==NULL || ny==0) printf("nx or ny is zero \n");
  447.     if (*nx!=0 && *ny != 0)   if (alloc_zdata(*nx,*ny)) return;
  448.     df = myfopen(fname,"r");
  449.     if (df==NULL) {*nx = 0; *ny = 0; return;}
  450.     for (;!feof(df);) {
  451.       if (fgets(buff,2000,df)!=NULL) {
  452.         if (*nx==0) {
  453.             strupr(buff);
  454.             *nx  = getkeyval(buff,"NX");
  455.             *ny  = getkeyval(buff,"NY");
  456.             dxmin = getkeyval(buff,"XMIN");
  457.             dymin = getkeyval(buff,"YMIN");
  458.             dxmax = getkeyval(buff,"XMAX");
  459.             dymax = getkeyval(buff,"YMAX");
  460.             if (*nx==0 || *ny==0) {
  461.                 gprint("Expecting ! NX 10 NY 10  in first line of data file \n");
  462.                 return;
  463.             }
  464.             mx = (*nx - 1)/xsample + 1;
  465.             my = (*ny - 1)/ysample + 1;
  466.             if (alloc_zdata(mx,my)) return;
  467.             fgets(buff,2000,df);
  468.         }
  469. check_again:
  470.         b = strlen(buff);
  471.         c = buff[b-1];
  472.         if (strchr(" \n\t",c)==NULL) { /* we're halfway thru a number */
  473.             buff[b] = getc(df);
  474.             buff[b+1] = 0;
  475.             goto check_again;
  476.         }
  477.         s = strchr(buff,'!');
  478.         if (s!=NULL) *s = 0;
  479.         s = strtok(buff," \t\n,");
  480.         for (;s!=NULL;) {
  481.             v = atof(s);
  482.             if (isdigit(*s) || *s=='-' || *s=='+' || *s=='.') {
  483.                 if (x>= *nx) {
  484.                     if (ycnt==ysample) {ycnt = 0; yy++;}
  485.                     x = 0; y++; ycnt++; xx = 0; xcnt = xsample;
  486.                     if (abortkey()) goto abort_data;
  487.                 }
  488.                 if (y>= *ny) {
  489.                     gprint("Too much data in data file %ld %d \n",y,*ny);
  490.                     return;
  491.                 }
  492.                 if (v < *zmin) *zmin = v;
  493.                 if (v > *zmax) *zmax = v;
  494.  
  495.                 if (xx<mx && xcnt==xsample && ycnt==ysample) {
  496.                     z[xx + yy * mx] = v;    
  497.                     xx++;    
  498.                     xcnt = 0; 
  499.                 }
  500.                 xcnt++; 
  501.                 x++;
  502.             } else gprint("Not a number {%s} \n",s);
  503.             s = strtok(NULL," \t\n,");
  504.         }    
  505.       }
  506.     }
  507.     fclose(df);
  508.     *ny = my;
  509.     *nx = mx;
  510.     return;
  511. abort_data:
  512.     fclose(df);
  513.     *nx = 0; *ny = 0;
  514.     return;
  515. }
  516. float *pntxyz;
  517. int npnts;
  518. pnt_alloc(int size)
  519. {
  520.     static cursize;
  521.     void *d;
  522.     if (size+10<cursize) return;
  523.     size = size*2;
  524.     d = farmalloc(size*sizeof(float));
  525.     if (d==NULL) {
  526.         gprint("Unable to allocate storage for POINTS data\n");
  527.         gle_abort("memory shortage\n");
  528.     }
  529.     if (cursize>0) memcpy(d,pntxyz,cursize*sizeof(float));
  530.     cursize = size;
  531.     pntxyz = d;
  532. }
  533. pass_points()
  534. {
  535.     double v;
  536.     char *s;
  537.     char *fname;
  538.     int i,nd,nc;
  539.     fname = getstrv();
  540.  
  541.     pnt_alloc(30);
  542.  
  543.     if (ct>ngtxt) {
  544.         gprint("Expecting POINTS filename.xyz \n");
  545.         return;
  546.     }
  547.             
  548.     df = myfopen(fname,"r");
  549.     if (df==NULL) return;
  550.     nd = 0;
  551.     for (;!feof(df);) {
  552.       if (fgets(buff,2000,df)!=NULL) {
  553.         s = strchr(buff,'!');
  554.         if (s!=NULL) *s = 0;
  555.         nc = 0;
  556.         s = strtok(buff," \t\n,");
  557.         for (;s!=NULL;) {
  558.             v = atof(s);
  559.             pnt_alloc(nd);
  560.             if (isdigit(*s) || *s=='-' || *s=='+' || *s=='.') {
  561.                 pntxyz[nd++] = v; nc++;
  562.             } else gprint("Not a number {%s} \n",s);
  563.             s = strtok(NULL," \t\n,");
  564.         }
  565.         if (nc>0 && nc!=3) {
  566.             gprint("Expecting 3 columns in data file, found %d (FATAL ERROR) \n",nc);
  567.         }
  568.       }
  569.     }
  570.     fclose(df);
  571.     npnts = nd;
  572.     sf.pntxyz = pntxyz;
  573.     sf.npnts = npnts;
  574. }
  575. hide_enddefaults() /* defaults after data and commands read */
  576. {
  577.     if (dxmin==dxmax) dxmax = nx-1;
  578.     if (dymin==dymax) dymax = ny-1;
  579.     if (!sf.xaxis.maxset)  sf.xaxis.max = dxmax;
  580.     if (!sf.yaxis.maxset)  sf.yaxis.max = dymax;
  581.     if (!sf.xaxis.minset)  sf.xaxis.min = dxmin;
  582.     if (!sf.yaxis.minset)  sf.yaxis.min = dymin;
  583.     if (!sf.zaxis.minset)  sf.zaxis.min = zmin;
  584.     if (!sf.zaxis.maxset)  sf.zaxis.max = zmax;
  585.     if (sf.zrotate==0 && sf.xrotate==0 && sf.yrotate==0) {
  586.         sf.xrotate = 60;
  587.         sf.yrotate = 50;
  588.         sf.zrotate = 20;    /* not needed as is corrected later*/
  589.     }
  590.     if (sf.eye_x== -1) {
  591.         sf.eye_x = sf.sizex/2.0;
  592.         sf.eye_y = sf.sizex/2.0;
  593.     }
  594.  
  595. }
  596.  
  597. hide_defaults()
  598. {
  599.     /* Setup some defaults, */
  600.     memset(&sf,0,sizeof(sf));
  601.     sf.sizey = sf.sizex = 18;
  602.     sf.sizey = sf.sizex = sf.sizez = 18;
  603.     sf.screenx = 18; sf.screeny = 18;
  604.     sf.eye_x = -1;
  605.     sf.zaxis.type = 2;
  606.     sf.yaxis.type = 1;
  607.     sf.xaxis.on = sf.yaxis.on = sf.zaxis.on = true;
  608.     sf.cube_hidden_on = true;
  609.     sf.cube_on = true;
  610.     sf.cube_front_on = false;
  611.     sf.xlines_on = true;
  612.     sf.ylines_on = true;
  613.     sf.hidden_on = true;
  614.     sf.top_on = true;    
  615.     sf.bot_on = false;
  616.     sf.base_hidden = sf.right_hidden = sf.back_hidden = true;
  617. }
  618. FILE *myfopen(char *fname, char *mode)
  619. {
  620.     FILE *f;
  621.     f = fopen(strlwr(fname),mode);
  622.     if (f==NULL) {
  623.         gprint("Unable to open {%s} \n\n",fname); perror("");
  624.         return NULL;
  625.     }
  626.     return f;
  627. }
  628. abortkey()
  629. {
  630.     if (!kbhit()) return false;
  631.     printf("Press ESC again: \n");
  632.     if (scr_getch()==27) return true;
  633.     else return false;
  634. }
  635. char *gle_top()
  636. {
  637.     char *s;
  638. #ifdef unix
  639.     return gleroot;
  640. #endif
  641. #ifdef __TURBOC__
  642.     return gleroot;
  643. #else
  644.     return "cgle_top:";
  645. #endif
  646. }
  647. char *gledir(char *s);
  648. char *bgidir()
  649. {
  650. #ifdef __TURBOC__
  651.     char *s;
  652.     s = getenv("GLE_BGI");
  653.     if (s==NULL) {
  654.         s = gledir("");
  655.     }
  656.     return s;
  657. #endif
  658. }
  659.  
  660. char *fontdir(char *fname)
  661. {
  662.     static char fbuff[80];
  663. #ifdef __TURBOC__
  664.     strcpy(fbuff,gle_top());
  665.     strcat(fbuff,"font\\");
  666. #else
  667.     strcpy(fbuff,"cgle_top:");
  668. #endif
  669. #ifdef unix
  670.     strcpy(fbuff,gle_top());
  671.     strcat(fbuff,"font/");
  672. #endif
  673.     strcat(fbuff,fname);
  674.     return &fbuff[0];
  675. }
  676. char *gletopdir(char *fname)
  677. {
  678.     static char fbuff[80];
  679.     strcpy(fbuff,gle_top());
  680.     strcat(fbuff,fname);
  681.     return fbuff;
  682. }
  683. char *gledir(char *fname)
  684. {
  685.     static char fbuff[80];
  686. #ifdef __TURBOC__
  687.     strcpy(fbuff,gle_top());
  688.     strcat(fbuff,"exe\\");
  689. #else
  690.     strcpy(fbuff,"cgle_top:");
  691. #endif
  692. #ifdef unix
  693.     strcpy(fbuff,gle_top());
  694. #endif
  695.     strcat(fbuff,fname);
  696.     return &fbuff[0];
  697. }
  698.